package shapp;

import hhh.utils.FileUtil;
import hhh.utils.LogUtil;
import hhh.remoteService.utils.ServiceRegister;
import hhh.remoteService.utils.rmi.RmiRegistry;
import com.ht.memcached.MemCachedConfigurator;
import com.ht.aems.dbservice.ConnectionFactory;
import com.ht.aems.ucp.AvcDevManager;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.rmi.RemoteException;

import devmodel.MOSqlPl;
import rtdb.RtMeasureHandler_MemoCached;
import rtdb.RtDataHandler_MemCached;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2012-1-13
 */
public class Main4Open3000 {
    public static void main(String[] args) throws FileNotFoundException, RemoteException {
        LogUtil.initialLog4j("shapp/shapp.log");
        RmiRegistry.setSpecifiedSocket();

        //load memcached config file
        String f = FileUtil.getRootDirectory() + "/_config/memcache.properties";
        System.out.println("Load memcached config file : " + f);
        MemCachedConfigurator.config(f);

        //load database access config file
        f = FileUtil.getRootDirectory() + "/_config/dba.properties";
        System.out.println("Load database access config file : " + f);
        ConnectionFactory.setConfig(new FileInputStream(f));

        AvcDevManager.instance.setPersistLayer(new MOSqlPl("AEMS_CTRL_DEVICES"));
        AvcDevManager.instance.loadFromDB();
        RemoteShApp.instance.getPointWriter().setRtMeasureQuery(new RtMeasureHandler_MemoCached());
        RemoteShApp.instance.getPointWriter().setRtDataHandler(new RtDataHandler_MemCached());
        ServiceRegister.registerService(ShApp.class, RemoteShApp.instance, "shapp");
        while(true) {
            RemoteShApp.instance.easWatcher();
            RemoteShApp.instance.ucpWatcher();
            try {
                Thread.sleep(5*60000l);
            } catch (InterruptedException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }


    }
}
